package com.example.controller.shopping;

import com.example.common.Result;

import com.example.model.entity.shopping.UserComment;
import com.example.model.vo.UserCommentVO;
import com.example.service.shopping.UserCommentService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户评价表前端操作接口
 **/
@RestController
@RequestMapping("/userComment")
@Api(tags = "用户评价接口")
public class UserCommentController {

    @Resource
    private UserCommentService userCommentService;


    /**
     * 根据药物ID查询对应评论信息
     */
    @ApiOperation(value = "根据药物ID查询")
    @GetMapping("/selectByMedicinesId/{medicinesId}")
    public Result selectByMedicinesId(@PathVariable Integer medicinesId) {
        List<UserCommentVO> userCommentVO =userCommentService.selectByMedicinesId(medicinesId);
        return Result.success(userCommentVO);
    }
    /**
     * 新增
     */
    @ApiOperation(value = "新增用户评价")
    @PostMapping("/add")
    public Result add(@RequestBody UserComment userComment) throws ParseException {
        userCommentService.add(userComment);
        return Result.success();
    }


    /**
     * 删除
     */
    @ApiOperation(value = "删除用户评价")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        userCommentService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除用户评价")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        userCommentService.deleteBatch(ids);
        return Result.success();
    }


    /**
     * 修改
     */
    @ApiOperation(value = "修改用户评价")
    @PutMapping("/update")
    public Result updateById(@RequestBody UserComment userComment) {
        userCommentService.updateById(userComment);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @ApiOperation(value = "根据ID查询用户评价")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        UserComment userComment = userCommentService.selectById(id);
        return Result.success(userComment);
    }

    /**
     * 查询所有
     */
    @ApiOperation(value = "查询所有用户评价")
    @GetMapping("/selectAll")
    public Result selectAll(UserComment userComment) {
        List<UserCommentVO> list = userCommentService.selectAll(userComment);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询用户评价")
    @GetMapping("/selectPage")
    public Result selectPage(UserComment userComment,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<UserCommentVO> page = userCommentService.selectPage(userComment, pageNum, pageSize);
        return Result.success(page);
    }

}
